package com.smartstate.dataManagement.controller;
import com.smartstate.dataManagement.dto.EnergyDTO;
import com.smartstate.dataManagement.dto.ObjMoudelDTO;
import com.smartstate.dataManagement.dto.common.TreeNode;
import com.smartstate.dataManagement.entity.ObjMoudel;
import com.smartstate.dataManagement.service.ObjMoudelService;
import com.smartstate.dataManagement.vo.ObjmiddleVo;
import com.smartstate.dataManagement.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>楼宇查询</p>
 * <p>@Author 陈永杰</p>
 * <p>@Date: 2022/8/17</p>
 * <p>@Time: 22:05</p>
 * <p>@version 1.0 <p>
 */
@RestController
@Api(tags = {"楼宇"})
@RequestMapping("/buildingModel")
public class ObjMoudelController {

    @Resource
    private ObjMoudelService objMoudelService;

    /**
     * 楼宇树结构
     * @return
     */
    @PostMapping("/selectBuilding")
    @ApiOperation(value = "楼宇查询")
    public  ResultVO<List<TreeNode>> selectMoudel(@RequestBody ObjMoudel objMoudel) {
        return ResultVO.ok(objMoudelService.selectMoudel(objMoudel.getType()));
    }

    /**
     *查出树所有的计算公式
     * @return
     */
    @PostMapping("/selectMetering")
    @ApiOperation(value = "查出树所有的计算公式")
    public ResultVO selectMetering(@RequestBody EnergyDTO item) {
        return ResultVO.ok(objMoudelService.selectMetering(item));
    }


    /**
     *组装树
     * @return
     */
    @PostMapping("/selectPowerTree")
    @ApiOperation(value = "组装树")
    public ResultVO selectPowerTree(@RequestBody EnergyDTO item) {
        return ResultVO.ok(objMoudelService.selectPowerTree(item));
    }


    /**
     * 添加图片
     * @return
     */
    @PostMapping("/updatePhoto")
    @ApiOperation(value = "添加图片")
    public ResultVO<Integer> updatePhoto(@RequestParam(value = "file", required = false) MultipartFile file, ObjMoudel objMoudel) {
        return ResultVO.ok(objMoudelService.updatePhoto(file,objMoudel));
    }




    /**
     *查看图片
     * @return
     */
    @PostMapping("/selectPhoto")
    @ApiOperation(value = "查看图片")
    public ResultVO selectPhoto(@RequestBody ObjMoudel item) {
        return ResultVO.ok(objMoudelService.selectPhoto(item.getId()));
    }



    /**
     * 添加设备 和楼宇 中间表
     * @param
     */
    @PostMapping("/addObjmiddle")
    @ApiOperation(value = "添加设备 和楼宇 中间表")
    public ResultVO<Integer> addPhoto(ObjmiddleVo objmiddleVo) {
        return ResultVO.ok(objMoudelService.addObjmiddle(objmiddleVo));
    }

    /**
     * 新增节点或修改节点
     * @param
     */
    @PostMapping("/addOrUpdateNode")
    @ApiOperation(value = "新增节点或修改节点")
    public com.smartstate.EnvironmentMonitor.vo.ResultVO addOrUpdateNode(@RequestBody ObjMoudelDTO objMoudelDTO) {
        if (objMoudelService.addOrUpdateNode(objMoudelDTO) == true){
            return com.smartstate.EnvironmentMonitor.vo.ResultVO.ok();
        }else {
            return com.smartstate.EnvironmentMonitor.vo.ResultVO.fail("失败");
        }
    }

    /**
     * 根据list中的节点id集合删除对于节点
     * @param objMoudelDTO
     * @return
     */
    @DeleteMapping("/delectNode")
    @ApiModelProperty(value = "删除节点")
    public com.smartstate.EnvironmentMonitor.vo.ResultVO delectNode(@RequestBody ObjMoudelDTO objMoudelDTO){
        if (objMoudelService.delectNode(objMoudelDTO.getList()) == true)
            return com.smartstate.EnvironmentMonitor.vo.ResultVO.ok();
        else
            return com.smartstate.EnvironmentMonitor.vo.ResultVO.fail();
    }

    /**
     * 根据id修改计量管理
     */
    @PostMapping("/updateMetering")
    @ApiOperation(value = "添加设备 和楼宇 中间表")
    public ResultVO<Integer> updateMetering(@RequestBody ObjMoudel  objMoudel) {
        return ResultVO.ok(objMoudelService.updateMetering(objMoudel.getId(),objMoudel.getMetering()),"修改成功");
    }




}